//
//  QRCodeTool.m
//  WeCommunity
//
//  Created by mac on 2017/6/14.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "QRCodeTool.h"
#import "CWebViewController.h"
#import "UITool.h"

@implementation QRCodeTool

#pragma mark - 识别二维码 ios > 8.0
+(NSMutableArray *)recognitionQRCodeWithImage:(UIImage *)image
{
    CIDetector*detector = [CIDetector detectorOfType:CIDetectorTypeQRCode
                                             context:nil
                                             options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }];
    NSArray * features = [detector featuresInImage:[CIImage imageWithCGImage:image.CGImage]];
    NSMutableArray * QRCodeUrlArray = [NSMutableArray array];
    for (int i = 0; i < features.count; i++) {
        CIQRCodeFeature *feature = [features objectAtIndex:i];
        NSString *scannedResult = feature.messageString;
        scannedResult = [scannedResult stringByTrimmingCharactersInSet:
                 [NSCharacterSet whitespaceAndNewlineCharacterSet]];
        [QRCodeUrlArray addObject:scannedResult];
    }
    return QRCodeUrlArray;
}

+(void)analysisQRCodeURLAndDealWithUrl:(NSString *)url
{
    NSString *  str = [url stringByTrimmingCharactersInSet:
                       [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    
    CWebViewController * webVC = [[CWebViewController alloc] init];
    webVC.linkUrl = str;
    [[UITool getCurrentVC].navigationController pushViewController:webVC animated:YES];
    
}


@end
